package org.eden.web.security;

import org.eden.rpc.common.entity.dao.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.ArrayList;
import java.util.List;

@Deprecated
//@Service
public class MyUserDetailsService implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        System.out.println("loadUserByUsername");
        MyUserDetails user = login(s);
        if (user != null) {
            // 数据库获取用户的权限
            List<Authority> authorities = new ArrayList<>();
            authorities.add(new Authority(1L, "admin"));
            user.setAuthorities(authorities);
        }
        return user;
    }

    // 模拟rpc调用
    private MyUserDetails login(String username) {
        if (!"zka".equals(username)) {
            return null;
        }
        String pwd = new BCryptPasswordEncoder().encode("1234");
        return null;
//        return new MyUserDetails(new User(1L, "zka", pwd, "", "", ""), null);
    }
}
